﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace oopPrijectDraft
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static Storage companyStorage;
        
        void LoadStorageFromFile()
        {

            //Retrieving file name
            string fileName;
            Microsoft.Win32.OpenFileDialog selectStorageFileDialogBox = new Microsoft.Win32.OpenFileDialog();
            if (selectStorageFileDialogBox.ShowDialog() != true)//the furst parameter is nullableq thats why we must use == true
            {
                if (false != selectStorageFileDialogBox.ShowDialog())
                {
                    MessageBox.Show(this, "Can't read that file.", "Decoding error", MessageBoxButton.OK,
                        MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.None);
                    
                }
                return;
            }
            else
            {
                fileName = selectStorageFileDialogBox.FileName;
            }
            //File name retrieved
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //Initializing company storage.
            companyStorage = StorageFactory.CreateStorage(fileName);
            //company storage initialized
            //Fill the item list with the storage inventory
            FillMerchandiseListBox();


        }
        void FillMerchandiseListBox()
        {
            foreach (Merchandise item in companyStorage.MerchandiseList)
            {
                merchandiseListBox.Items.Add(item.Model);
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            loadDataButton.Click+=loadDataButton_Click;
        }

        void loadDataButton_Click(object sender, RoutedEventArgs e)
        {
            LoadStorageFromFile();
        }
       
        private void startSearchButton_Click(object sender, RoutedEventArgs e)
        {

        }

        private void searchInputTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void Frame_Navigated_1(object sender, NavigationEventArgs e)
        {

        }

        private void addNewProductButton_Click(object sender, RoutedEventArgs e)
        {

        }

        private void merchandiseListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
    }
}
